<?php
/**
 * 在"编辑当前外观"页面上用CodeMirror 0.91 高亮代码编辑器
 * 
 * @package CodeMirror 
 * @author kinsunhoo
 * @version 1.0.0
 * @link http://codemirror.net/
 */
class CodeMirror_Plugin implements Typecho_Plugin_Interface
{
    /**
     * 激活插件方法,如果激活失败,直接抛出异常
     * 
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function activate()
    {
		Typecho_Plugin::factory('admin/theme-editor.php')->bottom = array('CodeMirror_Plugin', 'render');
    }
    /**
     * 禁用插件方法,如果禁用失败,直接抛出异常
     * 
     * @static
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function deactivate(){}
    
    /**
     * 获取插件配置面板
     * 
     * @access public
     * @param Typecho_Widget_Helper_Form $form 配置面板
     * @return void
     */
    public static function config(Typecho_Widget_Helper_Form $form)
    {
    }
    
    /**
     * 个人用户的配置面板
     * 
     * @access public
     * @param Typecho_Widget_Helper_Form $form
     * @return void
     */
    public static function personalConfig(Typecho_Widget_Helper_Form $form){}
    
    /**
     * 插件实现方法
     * 
     * @access public
     * @return void
     */
    public static function render()
    {
		$css_str='<style type="text/css"> 
		  .CodeMirror-line-numbers {
			width: 2.2em;
			color: #aaa;
			background-color: #eee;
			text-align: right;
			padding-right: .3em;
			font-size: 10pt;
			font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana;
			padding-top: .4em;
			line-height: 25px;
		  }
		</style> ';
		echo $css_str;
		
		$pluginUrl = Helper::options()->pluginUrl;
		echo "<script type=\"text/javascript\" charset=\"utf-8\" src=\"".$pluginUrl."/CodeMirror/files/js/codemirror.js\"></script>";
        echo '<script type="text/javascript">' 
		."var editor = CodeMirror.fromTextArea('content', \n{"
		."height: \"500px\","
		."parserfile: [ \"tokenizejavascript.js\", \"parsejavascript.js\",\"parsephphtmlmixed.js\"],"
		."stylesheet: [\"".$pluginUrl."/CodeMirror/files/css/xmlcolors.css\", \"".$pluginUrl."/CodeMirror/files/css/jscolors.css\", \"".$pluginUrl."/CodeMirror/files/css/csscolors.css\", \"".$pluginUrl."/CodeMirror/files/css/phpcolors.css\"],"
		."path: \"".$pluginUrl."/CodeMirror/files/js/\","
		."continuousScanning: 500,"
		."lineNumbers: true,"
		."textWrapping:false"
		."});"
		."</script> ';";
    }
}
